//
//  HMStatusRetweetView.m
//  HMWeiBoOC
//
//  Created by GD on 16/9/24.
//  Copyright © 2016年 geduo. All rights reserved.
//

#import "HMStatusRetweetView.h"
#import "UILabel+HMLabel.h"
#import "HMGlobalConst.h"
#import "HMStatusPictureView.h"

@interface HMStatusRetweetView ()

@property (nonatomic,strong) UILabel *contentLabel;

@property (nonatomic,strong) HMStatusPictureView *pictureView;

//记录转发发视图的底部约束.bottom
@property (nonatomic,strong) MASConstraint *retweetViewBottomConstraint;

@end

@implementation HMStatusRetweetView

-(void)setStatusViewModel:(HMStatusViewModel *)statusViewModel{
    _statusViewModel = statusViewModel;
    
    
    _contentLabel.text = statusViewModel.retweetContent;
    
    [self.retweetViewBottomConstraint uninstall];
    
    NSArray *picUrls = statusViewModel.status.retweeted_status.pic_urls;
    
    if (picUrls.count > 0) {
        self.pictureView.hidden = NO;
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            self.retweetViewBottomConstraint = make.bottom.equalTo(_pictureView).offset(HMHomeTableViewCellMargin);
        }];
        
        _pictureView.picUrls = picUrls;
    }else{
        self.pictureView.hidden = YES;
        
        [self mas_updateConstraints:^(MASConstraintMaker *make) {
            self.retweetViewBottomConstraint = make.bottom.equalTo(_contentLabel).offset(HMHomeTableViewCellMargin);
        }];
        
    }
}


-(instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    
    return self;
}

-(void)setupUI{
    self.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1];
    
    [self addSubview:self.contentLabel];
    [self addSubview:self.pictureView];
    
    [_contentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(HMHomeTableViewCellMargin);
        make.leading.equalTo(self).offset(HMHomeTableViewCellMargin);
        make.width.mas_equalTo(ScreenWidth - 2 * HMHomeTableViewCellMargin);
    }];
    
    [_pictureView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.leading.equalTo(_contentLabel);
        make.top.equalTo(_contentLabel.mas_bottom).offset(HMHomeTableViewCellMargin);
    }];
    
    
    [self mas_updateConstraints:^(MASConstraintMaker *make) {
        self.retweetViewBottomConstraint = make.bottom.equalTo(_pictureView).offset(HMHomeTableViewCellMargin);
    }];
}



#pragma mark 
-(UILabel *)contentLabel{

    if (!_contentLabel) {
        _contentLabel = [[UILabel alloc] initWithTextColor:[UIColor darkGrayColor] fontSize:[UIFont systemFontOfSize:14]];
        _contentLabel.numberOfLines = 0;
//        _contentLabel.backgroundColor = [UIColor orangeColor];
        _contentLabel.text = @"哈哈哈 , 新浪微博, 我来了~哈哈哈 , 新浪微博, 我来了~";
    }
    return _contentLabel;
}

-(HMStatusPictureView *)pictureView{
    if (!_pictureView ) {
        _pictureView = [[HMStatusPictureView alloc] init];
    }
    return _pictureView;
}

@end
